﻿using System;


namespace _1.PrintSquareRootWithUsingTryCatchFinally
{
    class PrintSquareRootWithUsingTryCatchFinally
    {
        static void Main(string[] args)
        {
            Console.Write("Integer number:");
            try
            {
                int number = int.Parse(Console.ReadLine());
                IsNegative(number);
                double sqrt = Math.Sqrt(number);
                Console.WriteLine("Square root is : " + sqrt);
            }
            catch (OverflowException ovex)
            {
                Console.WriteLine("Out of range is number! \n Message is: \" {0} \" ", ovex.Message);
            }
            catch (FormatException formatex)
            {
                Console.WriteLine("Incorrect inputted number! \n Message is: \" {0} \"", formatex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Some exception that's not catched in program. \n Message is: \" {0} \" ", ex.Message);

            }
            finally
            {
                Console.WriteLine("Good bye!");
            }
        }

        private static void IsNegative(int number)
        {
            if (number<0)
            {
                throw new ArithmeticException("Negative number!!! Ýou can't find Sqrt in this way.");
            }
        }
    }
}
